<template>
  <div>
    <p class="disa">
      <i class="dimension"></i>
      热门产品
    </p>
    <div class="popular-right_con">
      <div
        v-for="(item, index) in popularList"
        :key="index"
        class="popular-con"
        @click="handleView(item)"
      >
        <p>{{ item.serverType }}</p>
        <p>{{ item.serverName }}</p>
        <i v-if="item.topped" class="popularTags"></i>
        <div class="con">
          <span>CPU : {{ item.cpu || '无' }}</span>
          <span>内存 : {{ item.memory || '无' }}</span>
          <span>硬盘 : {{ item.hardDisk || '无' }}</span>
          <span>带宽 : {{ item.bandWidth || '无' }}</span>
          <span>防御 : {{ item.defense || '无' }}</span>
          <span>IP : {{ item.ip || '无' }}</span>
        </div>
        <p class="price">
          ¥ {{ item.price || 0 }}<i class="decorate">/{{ getMode(item.billingMode) }}</i>
        </p>
      </div>
    </div>
    <Buy-modal v-model:show="buyShow" :product="productInfo" shoppingCarEnums="GOV_CLOUD" />
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { hostList } from '@/api/zhengWuYun'

const popularList = ref<any>([])
const buyShow = ref(false) // 购买弹窗
const modeList = ref<any>([
  { label: '次', value: 0 },
  { label: '天', value: 1 },
  { label: '月', value: 30 },
  { label: '年', value: 365 }
])
const productInfo = ref<any>({})

onMounted(() => {
  getHostList()
})

// 获取热门产品
const getHostList = () => {
  hostList().then((res: any) => {
    popularList.value = res.rows
  })
}

// 获取计费方式
const getMode = (val: any) => {
  let row = modeList.value.find((item: any) => item.value == val)
  return row ? row.label : ''
}

// 跳转产品详情
const handleView = (item: any) => {
  productInfo.value = Object.assign({}, item)
  buyShow.value = true
}
</script>
<style lang="less" scoped>
.disa {
  width: 100%;
  height: 20px;
  display: flex;
  align-items: center;
  margin: 20px 0 10px;
  font-size: 16px;
  font-weight: 600;
  .dimension {
    display: inline-block;
    margin-right: 4px;
    width: 3px;
    height: 15px;
    background: #4098ff;
  }
}
.popular-right_con {
  display: flex;
  flex-wrap: wrap;
  .popular-con {
    width: 360px;
    margin-bottom: 20px;
    margin-right: 20px;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    position: relative;
    border: 1px solid transparent;
    transition: all 0.5s;
    padding: 10px;
    &:hover {
      cursor: pointer;
      box-shadow: 0 0 10px #c0c0c0;
    }
    .con {
      color: #909090;
      display: flex;
      flex-wrap: wrap;
      font-weight: 400;
      font-size: 12px;
      margin-top: 10px;
      span {
        margin-right: 12px;
        margin-bottom: 5px;
      }
    }
    .price {
      display: flex;
      align-items: baseline;
      font-size: 20px;
      font-weight: 600;
      color: #ff3939;
      .decorate {
        font-size: 12px;
      }
    }
  }
  .popularTags {
    display: inline-block;
    width: 32px;
    height: 14px;
    top: 5px;
    left: 150px;
    position: absolute;
    background: url(@/assets/img/client/cloudGovernment/Group2305.png) no-repeat center
      center / 100% 100%;
  }
}
</style>
